package com.itheima.d4_synchronized_code;

import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;

/**
 * 目标：模拟线程安全问题。
 */
public class ThreadTest {
    public static void main(String[] args) {
        Ticket02 ticket = new Ticket02();
        new Thread(ticket,"窗口1").start();
        new Thread(ticket,"窗口2").start();
        new Thread(ticket,"窗口3").start();

    }

    @Test
    public void test01(){
        Ticket01 ticket = new Ticket01();
        new Thread(ticket,"窗口1").start();
        new Thread(ticket,"窗口2").start();
        new Thread(ticket,"窗口3").start();
    }

    @Test
    public void test02() throws InterruptedException {
        Ticket02 ticket = new Ticket02();
        Thread t1 = new Thread(ticket, "窗口1");
        t1.start();
        new Thread(ticket,"窗口2").start();
        new Thread(ticket,"窗口3").start();

//        测试框架问题，测试框架执行完毕后，强制关闭子线程
/*        while (true){
            System.out.println("---");
            Thread.sleep(1000);
        }*/
    }
}


